﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MindBreaker.GameObjects
{
    public class BottomBar : PhysicObject
    {
        private static String BALL_TEXTURE_KEY = "DefaultBar";
        private const float BARMOVE = 3.5f;

        // Constructor
        public BottomBar(Game game, int posX, int posY, int speedX, int speedY)
            : base(game, BALL_TEXTURE_KEY, posX, posY, speedX, speedY)
        {
        }

        public void moveBar()
        {
            //Etat du clavier
            KeyboardState keyboard = Keyboard.GetState();
            if (this.LockCollision == 0) {
                if (this.isOutOfArea() == 0) {
                    //Si la touche Q est pressée
                    if (keyboard.IsKeyDown(Keys.Q) || keyboard.IsKeyDown(Keys.Left))
                        this.PosX -= BARMOVE;
                    else if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right))
                        this.PosX += BARMOVE;
                } else {
                    if (this.isOutOfArea() == 1) {
                        if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right))
                            this.PosX += BARMOVE;
                    } else if (this.isOutOfArea() == 2) {
                        if (keyboard.IsKeyDown(Keys.Q) || keyboard.IsKeyDown(Keys.Left))
                            this.PosX -= BARMOVE;
                    }
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            this.LockCollision = (this.LockCollision == 0) ? 0 : this.LockCollision - 1;
            this.moveBar();
            base.Update(gameTime);
        }
    }
}
